/**
 * 
 */
package com.handinfo.uimenu.window;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameMIDlet;
import com.handinfo.engine.GameManager;
import com.handinfo.game.AbstractGameActor;
import com.handinfo.game.ActorItem;
import com.handinfo.game.ActorRole;
import com.handinfo.game.ChatItem;
import com.handinfo.uimenu.AbsHyperLinker;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;

/**
 * @author venizeng
 * 
 */
public class UIChatInsert extends UIAbstractWindow implements ILBHandler
{

	private final int STATE_PIC = 1;// 插入图片状态
	private final int STATE_GOOD = 2;// 插入道具状态

	/***************************/
	// PIC
	/***************************/
	private final String PIC_TITLE = "插入表情";
	//
	private final int W_PIC_IMAGE = 16;// 一个图片切片宽度
	private final int H_PIC_IMAGE = 16;
	//
	private final int IW_PIC_IMAGEW = 15;// 切片之间的距离
	private final int IH_PIC_IMAGEH = 8;
	//
	private final int PIC_RW_IMAGE = W_PIC_IMAGE + IW_PIC_IMAGEW;
	private final int PIC_RH_IMAGE = H_PIC_IMAGE + IH_PIC_IMAGEH;
	//
	private final int PIC_NUM_ROWS = UIManager.IMAGE_BIAOQIAN.getHeight() / H_PIC_IMAGE;
	private final int PIC_NUM_COLS = UIManager.IMAGE_BIAOQIAN.getWidth() / W_PIC_IMAGE;
	//
	private final int PIC_W_BG = 150;// 插入图片时，背景的宽度
	private final int PIC_H_BG = 180;
	//
	private int PIC_X_INIT;// 图片的起始位置
	private int PIC_Y_INIT;
	/***************************/
	// Good
	/***************************/
	private final String GOOD_TITLE = "插入道具";
	private final int INDEX_GOOD_LABEL_FIRST = 1;
	private final int INDEX_GOOD_GOOD_FIRST = INDEX_GOOD_LABEL_FIRST + ActorItemLBHandler.NUM_LABEL_DIS;
	private final int GROUP_GOOD_LABEL = 1;
	private final int GROUP_GOOD_GOOD = 2;
	private final int GOOD_W_BG = UITools.W_BG;
	private final int GOOD_H_BG = UITools.H_BG;
	//
	private ActorItemLBHandler m_bag_handler;// 背包处理器
	private ActorItem[] m_good_items;// 背包

	/***************************/
	// 公用
	/***************************/
	private String m_title;

	/***************************/
	// Form
	/***************************/

	/**
	 * 放入从插入道具游戏中插入的字符串
	 */
	private static ArrayList s_list;
	//
	private static Form s_form;
	private static TextField s_textField;
	private static ChoiceGroup s_choiceGroup;
	private static StringItem s_warn;
	private static Command s_fayan;
	private static Command s_insert_face;
	private static Command s_insert_good;
	private static Command s_cancel;

	public UIChatInsert(int id)
	{
		super(id);
		initDis();
	}

	private void initDis()
	{
		PIC_X_INIT = ((PIC_W_BG - ((PIC_NUM_COLS - 1) * PIC_RW_IMAGE + W_PIC_IMAGE)) >> 1);
//		PIC_Y_INIT = UIManager.IMAGE_TITlE_MIDDLE.getHeight()
//				+ ((PIC_H_BG - ((PIC_NUM_ROWS - 1) * PIC_RH_IMAGE + H_PIC_IMAGE)
//				- UIManager.IMAGE_TITlE_MIDDLE.getHeight() - UITools.H_LABEL - UITools.IH_IMAGE_SOFT) >> 1);
	
		int h = PIC_H_BG -  UIManager.IMAGE_TITlE_MIDDLE.getHeight()  ;//除去标题的高度 - 内容框高度
		int picH = h - ((PIC_NUM_ROWS - 1) * PIC_RH_IMAGE + H_PIC_IMAGE) ;//除去图标高度
		PIC_Y_INIT =  UIManager.IMAGE_TITlE_MIDDLE.getHeight() + (picH >> 1) ;
	}

	/**
	 * 进入私聊 2012-3-7 下午02:58:47 venizeng
	 * @param name_recver
	 */
	public static void gotoSiliao(final long id_recver, final String name_recver)
	{
		s_list = new ArrayList(20, 10);//
		s_form = new Form("请输入聊天内容");
		s_textField = new TextField("内容：", "", ActorRole.NUM_MAX_CHAT, TextField.ANY);
		s_warn = new StringItem("", "");
		s_fayan = new Command("发言", Command.OK, 1);
		s_insert_face = new Command("插入表情", Command.OK, 2);
		s_insert_good = new Command("插入物品", Command.OK, 3);
		s_cancel = new Command("退出", Command.CANCEL, 1);
		s_form.append("收件人 ：" + name_recver);
		s_form.append(s_textField);
		s_form.append(s_warn);
		s_form.addCommand(s_fayan);
		s_form.addCommand(s_insert_face);
		s_form.addCommand(s_insert_good);
		s_form.addCommand(s_cancel);
		s_form.setCommandListener(new CommandListener() {

			public void commandAction(Command c, Displayable d)
			{
				if (c == s_fayan) {
					String str_content = s_textField.getString();
					if (str_content.equals("")) {
						s_warn.setText("请输入聊天内容");
						return;
					}
					String hyperStr = getHyperStr(str_content);
					// 发送
					GameManager.getInstance().m_game_message.sendChatItemCommitPrivate(id_recver, hyperStr);
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);

					// 加入到本地聊天记录
//					ChatItem item = ChatItem.createChatItemBySelf(ChatItem.TYPE_SI,name_recver, hyperStr,id_recver);
//					GameManager.getInstance().m_role.addToChat(item);
					// 清理资源
					clean();
				}
				else if (c == s_insert_face) {
					gotoInsetPic();
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_insert_good) {
					gotoInsetGood();
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_cancel) {
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
			}
		});
		Display.getDisplay(GameMIDlet.s_instance).setCurrent(s_form);
	}

	/**
	 * 清除 2012-3-7 下午06:27:59 venizeng
	 */
	private static void clean()
	{
		s_form = null;
		s_cancel = null;
		s_choiceGroup = null;
		s_fayan = null;
		s_insert_face = null;
		s_insert_good = null;
		s_list = null;
		s_textField = null;
		s_warn = null;
	}

	/**
	 * 转换成超链接形式 2012-3-7 下午05:20:46 venizeng
	 * @param str_content
	 * @return
	 */
	private static final String getHyperStr(String str_content)
	{
		// 转为超链接类型
		String hyperStr = intprePic(str_content);
		hyperStr = replaceGood(hyperStr);
		return hyperStr;
	}
	
	/**
	 * 全服喊话
	 * 2012-4-28 下午05:06:14
	 * venizeng
	 */
	public static void gotoServerSpeaker(final long speakerId){
		s_list = new ArrayList(20, 10);//
		s_form = new Form("请输入全服喊话内容");
		s_textField = new TextField("内容：", "", ActorRole.NUM_MAX_CHAT, TextField.ANY);
		//
		s_warn = new StringItem("", "");
		s_fayan = new Command("发言", Command.OK, 1);
		s_insert_face = new Command("插入表情", Command.OK, 2);
		s_insert_good = new Command("插入物品", Command.OK, 3);
		s_cancel = new Command("退出", Command.CANCEL, 1);
		s_form.append(s_textField);
		s_form.append(s_warn);
		s_form.addCommand(s_fayan);
		s_form.addCommand(s_insert_face);
		s_form.addCommand(s_insert_good);
		s_form.addCommand(s_cancel);
		s_form.setCommandListener(new CommandListener() {

			public void commandAction(Command c, Displayable d)
			{
				if (c == s_fayan) {
					String str_content = s_textField.getString();
					if (str_content.equals("")) {
						s_warn.setText("请输入聊天内容");
						return;
					}
					String hyperStr = getHyperStr(str_content);
					GameManager.getInstance().m_game_message.sendChatWorldBySpeaker(speakerId,hyperStr) ;
					// 清理资源
					clean();
					//返回低级界面
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_insert_face) {
					gotoInsetPic();
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_insert_good) {
					gotoInsetGood();
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_cancel) {
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
			}
		});
		Display.getDisplay(GameMIDlet.s_instance).setCurrent(s_form);
	}

	/**
	 * 公聊 2012-3-7 下午02:58:58 venizeng
	 */
	public static void gotoGongliao(int selIndex){
		s_list = new ArrayList(20, 10);//
		s_form = new Form("请输入聊天内容");
		s_textField = new TextField("内容：", "", ActorRole.NUM_MAX_CHAT, TextField.ANY);
		s_choiceGroup = new ChoiceGroup("请选择聊天频道", Choice.EXCLUSIVE);
		final String TEAM = "队伍";
		final String QU = "区";
		final String ZU = "家族";
		final String REALM = "阵营";
		final String WORLD = "世界";
		final String[] STRS = new String[4];
		int index = 0;
		// 世界 -世
		STRS[index] = WORLD;
		s_choiceGroup.append(String.valueOf(index) + ": " + WORLD, null);
		index++;
		// 阵营
		if (GameManager.getInstance().m_role.m_faction != AbstractGameActor.FACTION_ANY) {//有阵营
			STRS[index] = REALM;
			s_choiceGroup.append(String.valueOf(index) + ": " + REALM, null);
			index++;
		}
		// 组队 - 族
		if (GameManager.getInstance().m_role.m_position != 0) {//组队
			STRS[index] = ZU;
			s_choiceGroup.append(String.valueOf(index) + ": " + ZU, null);
			index++;
		}
		// 组队 - 队
		if (GameManager.getInstance().m_role.m_teamID != 0) {
			STRS[index] = TEAM;
			s_choiceGroup.append(String.valueOf(index) + ": " + TEAM, null);
			index++;
		}
		//
		s_choiceGroup.setSelectedIndex(selIndex, true);
		//
		s_warn = new StringItem("", "");
		s_fayan = new Command("发言", Command.OK, 1);
		s_insert_face = new Command("插入表情", Command.OK, 2);
		s_insert_good = new Command("插入物品", Command.OK, 3);
		s_cancel = new Command("退出", Command.CANCEL, 1);
		s_form.append(s_textField);
		s_form.append(s_choiceGroup);
		s_form.append(s_warn);
		s_form.addCommand(s_fayan);
		s_form.addCommand(s_insert_face);
		s_form.addCommand(s_insert_good);
		s_form.addCommand(s_cancel);
		s_form.setCommandListener(new CommandListener() {

			public void commandAction(Command c, Displayable d)
			{
				if (c == s_fayan) {
					String str_content = s_textField.getString();
					if (str_content.equals("")) {
						s_warn.setText("请输入聊天内容");
						return;
					}
					String hyperStr = getHyperStr(str_content);
					String temp = STRS[s_choiceGroup.getSelectedIndex()];
					if (temp == TEAM) {
						GameManager.getInstance().m_game_message.sendChatTeam(hyperStr);
						// 加入到本地聊天记录
//						GameManager.getInstance().m_role.addToChat(ChatItem.createChatItemToTeam(hyperStr));
					}
					else if (temp == QU) {
						GameManager.getInstance().m_game_message.sendChatQu(hyperStr);
						// 加入到本地聊天记录
//						GameManager.getInstance().m_role.addToChat(ChatItem.createChatItemToQu(hyperStr));
					}
					else if (temp == ZU) {
						GameManager.getInstance().m_game_message.sendChatFamily(hyperStr);
						// 加入到本地聊天记录
//						GameManager.getInstance().m_role.addToChat(ChatItem.createChatItemToFamily(hyperStr));
					}else if (temp == REALM) {
						GameManager.getInstance().m_game_message.sendChatRealm(hyperStr);
						// 加入到本地聊天记录
//						GameManager.getInstance().m_role.addToChat(ChatItem.createChatItemToRealm(hyperStr));
					}
					else if (temp == WORLD) {
						// 发送世界喊话,聊天频道中显示
						GameManager.getInstance().m_game_message.sendChatWorld(hyperStr);
					}
					// 清理资源
					clean();
					//返回低级界面
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_insert_face) {
					gotoInsetPic();
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_insert_good) {
					gotoInsetGood();
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
				else if (c == s_cancel) {
					Display.getDisplay(GameMIDlet.s_instance).setCurrent(GameMIDlet.s_canvas);
				}
			}
		});
		Display.getDisplay(GameMIDlet.s_instance).setCurrent(s_form);
	}

	/**
	 * 进入插入图片 2012-3-7 下午01:34:44 venizeng
	 */
	private static void gotoInsetPic()
	{
		UIChatInsert insert = (UIChatInsert) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_FACE);
		insert.setWindowStatus(insert.STATE_PIC);
		insert.m_index = 0;
		UIManager.getInstance().addWindow(insert);
	}

	/**
	 * 进入插入道具 2012-3-7 下午01:34:56 venizeng
	 */
	private static void gotoInsetGood()
	{
		UIChatInsert insert = (UIChatInsert) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_FACE);
		insert.setWindowStatus(insert.STATE_GOOD);
		insert.setWindowIndex(insert.INDEX_GOOD_LABEL_FIRST);
		UIManager.getInstance().addWindow(insert);
	}

	protected void actionOnStateChanged()
	{
		super.actionOnStateChanged();
		switch (m_state) {
			case STATE_GOOD:
				setBounds(UITools.X_BG, UITools.Y_BG, GOOD_W_BG, GOOD_H_BG);
				m_title = GOOD_TITLE;
				m_good_items = ActorRole.getActorItemCopys(GameManager.getInstance().m_role.m_bag_goods);
				m_bag_handler = new ActorItemLBHandler(this);
				m_bag_handler.setLabelByLabelId(ActorItem.TYPE_GOODS_ALL);
				//
				break;
			case STATE_PIC:
			default:
				setBounds(0, 0, PIC_W_BG, PIC_H_BG);
				setCentre();
				m_title = PIC_TITLE;
				break;
		}
	}

	protected void actionOnIndexChanged()
	{
		switch (m_state) {
			case STATE_GOOD:
				m_bag_handler.updateOnStateOrIndexChanged();
				break;
			case STATE_PIC:
			default:
				break;
		}
	}

	protected int countGroupId(int mIndex)
	{
		switch (m_state) {
			case STATE_GOOD:
				if (mIndex < INDEX_GOOD_GOOD_FIRST) {
					return GROUP_GOOD_LABEL;
				}
				else {
					return GROUP_GOOD_GOOD;
				}
			default:
				return 1;
		}
	}

	protected int countGroupIndex(int mGroupId, int mIndex)
	{
		switch (m_state) {
			case STATE_GOOD:
				switch (mGroupId) {
					case GROUP_GOOD_LABEL:
						return mIndex - getFirstIndex(ActorItemLBHandler.TYPE_LABEL);
					case GROUP_GOOD_GOOD:
					default:
						return mIndex - getFirstIndex(ActorItemLBHandler.TYPE_BAG);
				}
			default:
				return 1;
		}
	}

	/***************************/
	// LOGIC
	/***************************/

	protected void keyLogic()
	{
		switch (m_state) {
			case STATE_PIC:
				keyLogicOnPic();
				break;
			case STATE_GOOD:
			default:
				keyLogicOnGood();
				break;
		}
	}

	/**
	 * 取消操作 2012-3-7 下午01:38:52 venizeng
	 */
	private void gotoForm(String insertStr)
	{
		gotoForm(insertStr, "");
	}
	
	private void gotoForm(String insertStr,String alert)
	{
		close();
		// 返回到高级界面中
		int m_index_input = s_textField.getCaretPosition();
		String content = s_textField.getString();
		if (content.equals("")) {
			s_textField.setString(insertStr);
		}
		else {
			String temp = content.substring(0, m_index_input) + insertStr + content.substring(m_index_input, content.length());
			s_textField.setString(temp);
		}
		if (s_warn != null) {
			s_warn.setText(alert) ;
		}
		Display.getDisplay(GameMIDlet.s_instance).setCurrent(s_form);
	}

	private void cancel()
	{
		gotoForm("");
	}

	/**
	 * 点击某个道具插入 点击某张图片插入 2012-3-7 下午01:38:29 venizeng
	 */
	private void config()
	{
		close();
		String temp = null;
		switch (m_state) {
			case STATE_PIC:
				if (m_index < 10) {
					temp = "[pic0" + m_index + "]";
				}
				else {
					temp = "[pic" + m_index + "]";
				}
				if (isFitForForm(temp)) {
					gotoForm(temp);
				}else{
//					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "您的聊天字数过多，请精简文字");
//					gotoForm("") ;
					gotoForm("","您的聊天字数过多，请精简文字");
				}
				break;
			default:
				Object object = m_bag_handler.getCurrentBagItem();
				if (object == null) {
					cancel();
				}
				else {
					ActorItem item = (ActorItem) object;
					temp = new StringBuffer().append("[").append(item.m_name).append("]").toString();
					if (isFitForForm(temp)) {
						gotoForm(temp);
						s_list.addElement(temp);
						s_list.addElement(generateGoodMark(item));
					}else{
//						gotoForm("") ;
//						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "您的聊天字数过多，请精简文字");
						gotoForm("","您的聊天字数过多，请精简文字");
					}
				}
				break;
		}

	}

	/**
	 * 是否能将道具或者 2012-3-7 下午01:51:25 venizeng
	 * @return
	 */
	private boolean isFitForForm(String insertStr)
	{
		if (insertStr == null || insertStr.equals("")) {
			return false;
		}
		int maxSize = s_textField.getMaxSize();
		int currSize = s_textField.getString().length() + insertStr.length();
		if (currSize > maxSize) {
			return false;
		}
		return true;
	}

	/***************************/
	// LOGIC - pic
	/***************************/
	private void keyLogicOnPic()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			cancel();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			config();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (m_index < PIC_NUM_COLS) {
				m_index += (PIC_NUM_ROWS - 1) * PIC_NUM_COLS;
			}
			else {
				m_index -= PIC_NUM_COLS;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			int num = (PIC_NUM_ROWS - 1) * PIC_NUM_COLS;
			if (m_index >= num) {
				m_index -= num;
			}
			else {
				m_index += PIC_NUM_COLS;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			if (m_index == 0) {
				m_index = PIC_NUM_ROWS * PIC_NUM_COLS - 1;
			}
			else {
				m_index--;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			if (m_index == PIC_NUM_ROWS * PIC_NUM_COLS - 1) {
				m_index = 0;
			}
			else {
				m_index++;
			}
		}
	}

	/**
	 * 解释 2012-3-7 下午03:10:07 venizeng
	 * @param content
	 * @return
	 */
	public static String intprePic(String content)
	{
		int index = 0;
		int startIndx = 0;
		while ((index = content.indexOf("[pic", startIndx)) != -1) {
			int endIndx = index + 6;
			if (content.charAt(endIndx) != ']') {
				startIndx = index + 1;
			}
			else {
				String num = content.substring(index + 4, endIndx);
				boolean isNumFitfor = true;
				int iNum = 0;
				try {
					iNum = Integer.parseInt(num);
				}
				catch (Exception e) {
					startIndx = index + 1;
					isNumFitfor = false;
				}
				if (isNumFitfor) {
					if (iNum < 0 || iNum >= 20) {
						startIndx = index + 1;
					}
					else {
						if (isNumFitfor) {
							String newStr = "<pic i=" + iNum + "></pic>";
							String temp = content.substring(index, endIndx + 1);
							content = Tools.modifyString(content, temp, newStr);
						}
					}
				}
			}
		}
		return content;
	}

	/***************************/
	// LOGIC-GOOD
	/***************************/
	private void keyLogicOnGood()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			cancel();
			return;
		}
		switch (m_groupId) {
			case GROUP_GOOD_LABEL: {
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_LABEL);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						// 未处理
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
			}
				break;
			case GROUP_GOOD_GOOD:
			default: {
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
							config();
						}
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
			}
				break;
		}
	}

	public static final String replaceGood(String content)
	{
		if (s_list == null) {
			return content;
		}
		for (int i = 0, length = s_list.size(); i < length; i += 2) {
			String disContent = (String) s_list.elementAt(i);
			String hyperStr = (String) s_list.elementAt(i + 1);
			while (content.indexOf(disContent) != -1) {
				content = Tools.modifyString(content, disContent, hyperStr);
			}
		}
		return content;
	}

	/**
	 * 将文字转为超链接形式 [item001] 转换为 <mark t=1 i=10000>道具</mark> 2012-3-7 下午03:14:48 venizeng
	 * @param content
	 * @return
	 */
	public static String generateGoodMark(ActorItem item)
	{
		String newStr = new StringBuffer(40).append("<mark t=").append(AbsHyperLinker.URL_ACTORITEM)
				.append(" i=").append(item.m_guid).append(", u=1").append(">")
//			.append(" i=").append(item.m_guid).append(">")
				.append(item.m_name).append("</mark>").toString();
		return newStr;
	}

	public Object[] getBagDatas()
	{
		return m_good_items;
	}

	public int getFirstIndex(int idComp)
	{
		switch (idComp) {
			case AbsLBHandler.TYPE_BAG:
				return INDEX_GOOD_GOOD_FIRST;
			case AbsLBHandler.TYPE_LABEL:
			default:
				return INDEX_GOOD_LABEL_FIRST;
		}
	}

	public int getGroupIndex()
	{
		return m_groupIndex;
	}

	public int getLeftIndex()
	{
		switch (this.m_groupId) {
			case GROUP_GOOD_LABEL:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
			case GROUP_GOOD_GOOD:
				return INDEX_GOOD_GOOD_FIRST - 1;
			default:
				return 1;
		}
	}

	public int getRightIndex()
	{
		switch (this.m_groupId) {
			case GROUP_GOOD_LABEL:
				return INDEX_GOOD_GOOD_FIRST;
			case GROUP_GOOD_GOOD:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
			default:
				return 1;
		}
	}

	public int getUpIndex()
	{
		switch (this.m_groupId) {
			case GROUP_GOOD_LABEL:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
			case GROUP_GOOD_GOOD:
				return m_bag_handler.getCurrentLabelWindowIndex();
			default:
				return 1;
		}
	}

	public int getDownIndex()
	{
		switch (this.m_groupId) {
			case GROUP_GOOD_LABEL:
				return INDEX_GOOD_GOOD_FIRST;
			case GROUP_GOOD_GOOD:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
			default:
				return 1;
		}
	}

	public int getWindowIndex()
	{
		return m_index;
	}

	/***************************/
	// PAINT
	/***************************/
	protected void paintContent(Graphics g)
	{
		switch (m_state) {
			case STATE_PIC:
				paintContentOnPic(g);
				break;
			case STATE_GOOD:
			default:
				paintContentOnGood(g);
				break;
		}
	}

	/***************************/
	// PAINT - pic
	/***************************/
	private void paintContentOnPic(Graphics g)
	{
		// 绘制背景
		UITools.drawWindowBackgroud(g, m_x, m_y, m_w, m_h);
		// 绘制标题
		UITools.paintBackgroundTitleOn240320(g, m_x, m_y, m_w, m_h, m_title);
	//	绘制按钮
		UITools.paintBackgroundButton(g, m_x, m_y, m_w, m_h,false,false);
		
		UITools.paintBorderConer(g, m_x, m_y, m_w, m_h);
		//
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipW = g.getClipWidth();
		int clipH = g.getClipHeight();
		int tempY = m_y + PIC_Y_INIT;
		int num = 0;
		for (int i = 0; i < PIC_NUM_ROWS; i++) {
			int tempX = m_x + PIC_X_INIT;
			for (int j = 0; j < PIC_NUM_COLS; j++) {
				g.setClip(tempX, tempY, W_PIC_IMAGE, H_PIC_IMAGE);
				g.drawImage(UIManager.IMAGE_BIAOQIAN, tempX - (j * W_PIC_IMAGE), tempY - (i * H_PIC_IMAGE), 0);
				if (num == m_index) {
					UITools.paintFocusBox(g, tempX - 2, tempY - 2, W_PIC_IMAGE + 4, H_PIC_IMAGE + 4);
				}
				tempX += PIC_RW_IMAGE;
				num++;
			}
			tempY += PIC_RH_IMAGE;
		}
		g.setClip(clipX, clipY, clipW, clipH);
	}

	/***************************/
	// PAINT - good
	/***************************/
	private void paintContentOnGood(Graphics g)
	{
		UITools.paintBackGround(g, m_x, m_y, m_w, m_h, m_title);
		m_bag_handler.setInitXY(m_y + UITools.INITY_CONTENT);
		m_bag_handler.paintLabel(g);
		m_bag_handler.paintBag(g);
		m_bag_handler.paintDrag(g);
		m_bag_handler.paintBagFocused(g);
		m_bag_handler.paintDescribe(g);
	}

}
